package com.itheima.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("page")
public class PageController {

    //1. 根目录
    //2. WEB-INF 下
    // 根目录 浏览器访问的时候 直接访问  浏览器无法访问WEB-INF 下的页面

    @RequestMapping("page1")
    public String page1(){
        //forward  webinf下 不支持 redirect
        return "page";
    }

    @RequestMapping("page2")
    public String page2(String name, HttpServletRequest request){
        request.setAttribute("name",name);
        return "page";
    }

    @RequestMapping("page3")
    public String page3(String name, Model model){
//        request.setAttribute("name",name);
        model.addAttribute("name",name);
        return "page";
    }

    //用的最多 建议使用的
    @RequestMapping("page4")
    public ModelAndView page4(String name){
        ModelAndView modelAndView = new ModelAndView("page");
        modelAndView.addObject("name",name);

        return modelAndView;
    }
}
